local jiezi = fk.CreateSkill{
  name = "iberia__jiezi",
}

Fk:loadTranslationTable{
  [jiezi.name] = "截辎",
  [":"..jiezi.name] = "攻击范围内的角色的摸牌阶段，你可以打出一张【杀】并令其选择两项："
  .."1.打出手牌中的一张【闪】；2.少摸一张牌；3.令你摸一张牌。",

  [jiezi.name.."-invoke"] = "截辎：可以打出【杀】并令 %src 选择",
  [jiezi.name.."-choose"] = "截辎：请选择两项",

  [jiezi.name.."-jink"] = "打出【闪】",
  [jiezi.name.."-quit"] = "少摸一张牌",
  [jiezi.name.."-draw"] = "令 %src 摸一张牌",
}

jiezi:addEffect(fk.DrawNCards, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player)
    return player:hasSkill(jiezi.name) and player:inMyAttackRange(target)
  end,
  on_cost = function (self, event, target, player)
    local room = player.room
    local response = room:askToResponse(player, {
      pattern = "slash",
      skill_name = jiezi.name,
      prompt = jiezi.name.."-invoke:"..target.id,
    })
    if not response then return end
    event:setCostData(self, response)
    return true
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:responseCard(event:getCostData(self))
    if target.dead then return end
    local all_choices = { jiezi.name.."-jink", jiezi.name.."-quit", jiezi.name.."-draw:"..player.id }
    local choices = table.simpleClone(all_choices)
    local _, ret = room:askToUseActiveSkill(target, {
      skill_name = "iberia__jiezi_active",
      prompt = jiezi.name.."-choose",
      cancelable = false,
      extra_data = {
        all_choices = all_choices,
        choices = choices
      },
    })
    if not ret then return end
    local choosed = string.split(ret.interaction, ",")
    if table.contains(choosed, all_choices[1]) then
      room:responseCard{
        from = target,
        card = Fk:getCardById(ret.cards[1]),
      }
    end
    if table.contains(choosed, all_choices[2]) and data.n > 0 then
      data.n = data.n - 1
    end
    if table.contains(choosed, all_choices[3]) and not player.dead then
      room:drawCards(player, 1, jiezi.name)
    end
  end
})

return jiezi